<?php
namespace backend\models\activeRecords;

use common\libs\Constants;
use Yii;
use yii\db\ActiveRecord;

/**
 * This is the model class for table "{{%t_game}}".
 *
 * @property int $game_id
 * @property int $game_type 游戏类型（是否混服）
 * @property string $game_no
 * @property string $game_name
 * @property string $game_logo
 * @property string $game_logo2
 * @property string $game_logo3
 * @property string $game_logo4
 * @property string $game_logo5
 * @property string $game_logo6
 * @property string $game_logo7
 * @property string $game_logo8
 * @property string $game_logo9
 * @property string $game_depict
 * @property string $game_website
 * @property string $game_bbs
 * @property string $game_freshman
 * @property int $game_is_show
 * @property int $game_is_focus
 * @property int $game_is_best
 * @property int $game_is_hot
 * @property int $game_is_topbar
 * @property int $game_sort
 * @property int $game_money_per
 * @property string $game_money_name
 * @property int $game_pay_role
 * @property string $game_login_gateway
 * @property string $game_pay_gateway
 * @property string $game_port_config1
 * @property string $game_port_config2
 * @property string $game_port_config3
 * @property string $game_port_config4
 * @property string $game_port_config5
 * @property string $game_port_s1
 * @property string $game_port_s2
 * @property string $game_port_s3
 * @property string $game_port_s4
 * @property string $game_port_s5
 * @property string $game_rate 游戏费率
 */
class TGame extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%t_game}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['game_type', 'game_is_show', 'game_is_focus', 'game_is_best', 'game_is_hot', 'game_is_topbar', 'game_sort', 'game_money_per', 'game_pay_role'], 'integer'],
            [['game_rate'], 'number'],
            [['game_no', 'game_name', 'game_logo', 'game_logo2', 'game_logo3', 'game_logo4', 'game_logo5', 'game_logo6', 'game_logo7', 'game_logo8', 'game_logo9', 'game_website', 'game_bbs', 'game_freshman', 'game_money_name', 'game_login_gateway', 'game_pay_gateway', 'game_port_s1', 'game_port_s2', 'game_port_s3', 'game_port_s5'], 'string', 'max' => 50],
            [['game_depict', 'game_port_config1', 'game_port_config2', 'game_port_config3', 'game_port_config4', 'game_port_config5', 'game_port_s4'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'game_id' => Yii::t('app', 'Game ID'),
            'game_type' => Yii::t('app', '游戏类型（是否混服）'),
            'game_no' => Yii::t('app', 'Game No'),
            'game_name' => Yii::t('app', 'Game Name'),
            'game_logo' => Yii::t('app', 'Game Logo'),
            'game_logo2' => Yii::t('app', 'Game Logo2'),
            'game_logo3' => Yii::t('app', 'Game Logo3'),
            'game_logo4' => Yii::t('app', 'Game Logo4'),
            'game_logo5' => Yii::t('app', 'Game Logo5'),
            'game_logo6' => Yii::t('app', 'Game Logo6'),
            'game_logo7' => Yii::t('app', 'Game Logo7'),
            'game_logo8' => Yii::t('app', 'Game Logo8'),
            'game_logo9' => Yii::t('app', 'Game Logo9'),
            'game_depict' => Yii::t('app', 'Game Depict'),
            'game_website' => Yii::t('app', 'Game Website'),
            'game_bbs' => Yii::t('app', 'Game Bbs'),
            'game_freshman' => Yii::t('app', 'Game Freshman'),
            'game_is_show' => Yii::t('app', 'Game Is Show'),
            'game_is_focus' => Yii::t('app', 'Game Is Focus'),
            'game_is_best' => Yii::t('app', 'Game Is Best'),
            'game_is_hot' => Yii::t('app', 'Game Is Hot'),
            'game_is_topbar' => Yii::t('app', 'Game Is Topbar'),
            'game_sort' => Yii::t('app', 'Game Sort'),
            'game_money_per' => Yii::t('app', 'Game Money Per'),
            'game_money_name' => Yii::t('app', 'Game Money Name'),
            'game_pay_role' => Yii::t('app', 'Game Pay Role'),
            'game_login_gateway' => Yii::t('app', 'Game Login Gateway'),
            'game_pay_gateway' => Yii::t('app', 'Game Pay Gateway'),
            'game_port_config1' => Yii::t('app', 'Game Port Config1'),
            'game_port_config2' => Yii::t('app', 'Game Port Config2'),
            'game_port_config3' => Yii::t('app', 'Game Port Config3'),
            'game_port_config4' => Yii::t('app', 'Game Port Config4'),
            'game_port_config5' => Yii::t('app', 'Game Port Config5'),
            'game_port_s1' => Yii::t('app', 'Game Port S1'),
            'game_port_s2' => Yii::t('app', 'Game Port S2'),
            'game_port_s3' => Yii::t('app', 'Game Port S3'),
            'game_port_s4' => Yii::t('app', 'Game Port S4'),
            'game_port_s5' => Yii::t('app', 'Game Port S5'),
            'game_rate' => Yii::t('app', '游戏费率'),
        ];
    }

    public static function getGameList(){
        $gameInfo = TGame::find()
            ->where('game_is_show = :game_is_show',[':game_is_show'=>Constants::Status_Enable])
            ->all();
        return $gameInfo;
    }

    public static function getGameListOptions(){
        $gameInfo = TGame::find()
            ->where('game_is_show = :game_is_show',[':game_is_show'=>Constants::Status_Enable])
            ->all();
        $list = [''=>'请选择'];
        foreach($gameInfo as $value){
            $list[$value->game_id] = $value->game_name;
        }
        return $list;
    }

    public static function getGameNameListOptions(){
        $gameInfo = TGame::find()
            ->where('game_is_show = :game_is_show',[':game_is_show'=>Constants::Status_Enable])
            ->all();
        $list = [''=>'请选择'];
        foreach($gameInfo as $value){
            $list[$value->game_name] = $value->game_name;
        }
        return $list;
    }

    public static function getGameListEliminate($model){
        $gameList = self::getGameList();
        $guildGameList = [];
        foreach($model as $value){
            array_push($guildGameList,$value->game_id);
        }
        foreach($gameList as $key=>$value){
            if(in_array(strval($value->game_id),$guildGameList)){
                unset($gameList[$key]);
            }
        }
        return $gameList;
    }

}
